from fastapi import FastAPI, APIRouter
import uvicorn
import os
import sys

# 导入hello模块中的路由器
from utils.hello import hello_router

# 定义API前缀
API_PREFIX = "/api"

# 创建FastAPI应用
app = FastAPI(title="FastAPI Test Project")

# 创建路由器，添加前缀
router = APIRouter(prefix=API_PREFIX)

@router.get("/root")
async def root():
    return {"message": "helloworld"}

# 将路由器包含到应用中
app.include_router(router)
app.include_router(hello_router)  # 添加hello模块的路由器

# 添加根路由重定向到API文档
@app.get("/", include_in_schema=False)
async def redirect_to_docs():
    from fastapi.responses import RedirectResponse
    return RedirectResponse(url="/docs")

# 直接运行应用
if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000) 